package lunceneDemo;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.ExitableDirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.SegmentReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.QueryBuilder;
import org.apache.lucene.util.Version;

public class LunceRam {
	public static void main(String[] args) throws IOException {
		
//	    final List<String> stopWords = Arrays.asList(
//	    		"的","和","或"
//	    	    );
//	    final CharArraySet stopSet = new CharArraySet(stopWords, false);
//	    CharArraySet stopWords1 = CharArraySet.unmodifiableSet(stopSet); 
//		
//		Directory directory=new  RAMDirectory();
//		Analyzer analyzer=new StandardAnalyzer(stopWords1);
//		analyzer.setVersion(Version.LUCENE_6_5_0);
//		IndexWriterConfig config=new IndexWriterConfig(analyzer);
//		IndexWriter indexWriter=new IndexWriter(directory, config);
//		
//		String name1="当你使用具有显式依赖关系的模块和模块化的 JDK 时程序";
//		String name2="你的应用程序模块现在将声明其对其他应用程";
//		String name3="程序为程序什么最小的运行时环境";
//		
//		Document d1=new Document();
//		d1.add(new TextField("name", name1, Field.Store.YES));
//		indexWriter.addDocument(d1);
//		Document d2=new Document();
//		d2.add(new TextField("name", name2, Field.Store.YES));
//		Document d3=new Document();
//		indexWriter.addDocument(d2);
//		d3.add(new TextField("name", name3, Field.Store.YES));
//		indexWriter.addDocument(d3);
//		
//		indexWriter.flush();
//		indexWriter.commit();
//		indexWriter.close();
//		
//		IndexReader indexReader=DirectoryReader.open(directory);
//		IndexSearcher searcher=new IndexSearcher(indexReader);
//		
//		
//		QueryBuilder builder=new QueryBuilder(analyzer);
//		Query query = builder.createPhraseQuery("name", "程序");
//		
//		
//		TopDocs search = searcher.search(query, 10);
//		System.out.println(search.totalHits);
//		ScoreDoc[] scoreDocs = search.scoreDocs;
//		for (ScoreDoc scoreDoc : scoreDocs) {
//			System.out.println(scoreDoc);
//		}
		
	}
}
